package com.company.gxcpc2020;

import java.math.BigInteger;
import java.util.Scanner;

public class GxcpcB {
    public static int n;
    public static int[] fun;
    public static int[] ks;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            n = sc.nextInt();
            int q = sc.nextInt();
            fun = new int[n];
            ks = new int[n];
            for (int i = 0; i < n; i++) {
                fun[i] = sc.nextInt();
                ks[i] = sc.nextInt();
            }
            for (int i = 0; i < q; i++) {
                int r = sc.nextInt();
                int x = df(r, sc.nextInt());
                System.out.println(x);
            }
        }
    }

    public static int df(int r, int x) {
        if (r <= 0) {
            return x;
        }
        for (int i = r - 1; i >= 0; i--) {
            int fun = GxcpcB.fun[i];
            switch (fun) {
                case 1:
                    x = f1(x, ks[i]);
                    break;
                case 2:
                    x = f2(x, ks[i]);
                    break;
                default:
                    x = f3(x, ks[i]);
            }
        }
        return x;
    }

    public static int f1(int x, int k) {
        return (x + k) % 101;
    }

    public static int f2(int x, int k) {
        return (x * k) % 101;
    }

    public static int f3(int x, int k) {
        return BigInteger.valueOf(x).pow(k).mod(BigInteger.valueOf(101)).intValue();
    }

}
